package com.anlu.concurrent.ch6.scheduled;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 * Description:TODO 详细描述
 * <p>
 * Copyright: 天津联想协同科技有限公司
 * <p>
 *
 * @author anlu
 * @date 2021/10/29 11:35
 */
public class ScheduleWorker implements Runnable{
    /**
     * 普通任务类型
     */
    public final static int Normal = 0;
    /**
     * 会抛出异常的任务类型
     */
    public final static int HasException = -1;
    /**
     * 抛出异常但会捕捉的任务类型
     */
    public final static int ProcessException = 1;
    public static SimpleDateFormat formater = new SimpleDateFormat(
            "yyyy-MM-dd HH:mm:ss");

    private int taskType;
    public ScheduleWorker(int taskType) {
        this.taskType = taskType;
    }
    @Override
    public void run() {
        if(taskType==HasException) {
            System.out.println(formater.format(new Date())+" Exception made...");
            throw new RuntimeException("HasException Happen");
        }else if(taskType==ProcessException) {
            try {
                System.out.println(formater.format(new Date())
                        +" Exception made,but catch");
                throw new RuntimeException("HasException Happen");
            }catch(Exception e) {
                System.out.println(" Exception be catched");
            }
        }else {
            System.out.println(" Normal ...."+formater.format(new Date()));
        }
    }
}
